#!/bin/sh

#rm -rf usr/lib/girepository-1.0
rm -rf usr/share/gir-1.0
rm -rf usr/share/gtk-2.0/demo
rm -f usr/bin/gtk-demo

# defaults to awaita
rm -f usr/share/gtk-2.0/gtkrc

# debian
if [ -f usr/lib/libgtk2.0-0/gtk-query-immodules-2.0 ] ; then
	mkdir -p usr/bin
	mv usr/lib/libgtk2.0-0/gtk-query-immodules-2.0 usr/bin/
	ln -sv ../../bin/gtk-query-immodules-2.0 usr/lib/libgtk2.0-0/gtk-query-immodules-2.0 
fi

# slackware
if [ -d usr/share/themes ] ; then
	find usr/share/themes -type d -name 'gtk-2.0-key' | \
	while read d ; do mv $d ${d%-key} ; done
fi

#==============================================================
#upups and dpups don't usually include libgtk2.0-common... damn
#==============================================================

if [ ! -f etc/gtk-2.0/im-multipress.conf ] ; then
	mkdir -p etc/gtk-2.0
	cat > etc/gtk-2.0/im-multipress.conf <<EOF
# The example configuration below imitates the behavior of a standard mobile
# phone by a major manufacturer, with German language setting.
[keys]
KP_1 = .;,;?;!;';";1;-;(;);@;/;:;_
KP_2 = a;b;c;2;ä;à;á;ã;â;å;æ;ç
KP_3 = d;e;f;3;è;é;ë;ê;ð
KP_4 = g;h;i;4;ì;í;î;ï
KP_5 = j;k;l;5;£
KP_6 = m;n;o;6;ö;ò;ó;ô;õ;ø;ñ
KP_7 = p;q;r;s;7;ß;$
KP_8 = t;u;v;8;ü;ù;ú;û
KP_9 = w;x;y;z;9;ý;þ
KP_0 = \s;0
EOF
fi

mkdir -p usr/share/themes/Default/gtk-2.0
cat > usr/share/themes/Default/gtk-2.0/gtkrc <<EOF
# gtkrc default theme
style "default"
{
  font_name="DejaVu Sans 12"
}
class "GtkWidget" style "default"
EOF

if [ ! -f usr/share/themes/Emacs/gtk-2.0/gtkrc ] ; then
	mkdir -p usr/share/themes/Emacs/gtk-2.0
	cat > usr/share/themes/Emacs/gtk-2.0/gtkrc <<EOF
#
# Bindings for GtkTextView and GtkEntry
#
binding "gtk-emacs-text-entry"
{
  bind "<ctrl>b" { "move-cursor" (logical-positions, -1, 0) }
  bind "<shift><ctrl>b" { "move-cursor" (logical-positions, -1, 1) }
  bind "<ctrl>f" { "move-cursor" (logical-positions, 1, 0) }
  bind "<shift><ctrl>f" { "move-cursor" (logical-positions, 1, 1) }

  bind "<alt>b" { "move-cursor" (words, -1, 0) }
  bind "<shift><alt>b" { "move-cursor" (words, -1, 1) }
  bind "<alt>f" { "move-cursor" (words, 1, 0) }
  bind "<shift><alt>f" { "move-cursor" (words, 1, 1) }

  bind "<ctrl>a" { "move-cursor" (paragraph-ends, -1, 0) }
  bind "<shift><ctrl>a" { "move-cursor" (paragraph-ends, -1, 1) }
  bind "<ctrl>e" { "move-cursor" (paragraph-ends, 1, 0) }
  bind "<shift><ctrl>e" { "move-cursor" (paragraph-ends, 1, 1) }

  bind "<ctrl>w" { "cut-clipboard" () }
  bind "<ctrl>y" { "paste-clipboard" () }

  bind "<ctrl>d" { "delete-from-cursor" (chars, 1) }
  bind "<alt>d" { "delete-from-cursor" (word-ends, 1) }
  bind "<ctrl>k" { "delete-from-cursor" (paragraph-ends, 1) }
  bind "<alt>backslash" { "delete-from-cursor" (whitespace, 1) }

  bind "<alt>space" { "delete-from-cursor" (whitespace, 1)
                      "insert-at-cursor" (" ") }
  bind "<alt>KP_Space" { "delete-from-cursor" (whitespace, 1)
                         "insert-at-cursor" (" ")  }

  #
  # Some non-Emacs keybindings people are attached to
  #
  bind "<ctrl>u" {
     "move-cursor" (paragraph-ends, -1, 0)
     "delete-from-cursor" (paragraph-ends, 1)
  }
  bind "<ctrl>h" { "delete-from-cursor" (chars, -1) }
  bind "<ctrl>w" { "delete-from-cursor" (word-ends, -1) }
}

#
# Bindings for GtkTextView
#
binding "gtk-emacs-text-view"
{
  bind "<ctrl>p" { "move-cursor" (display-lines, -1, 0) }
  bind "<shift><ctrl>p" { "move-cursor" (display-lines, -1, 1) }
  bind "<ctrl>n" { "move-cursor" (display-lines, 1, 0) }
  bind "<shift><ctrl>n" { "move-cursor" (display-lines, 1, 1) }

  bind "<ctrl>space" { "set-anchor" () }
  bind "<ctrl>KP_Space" { "set-anchor" () }
}

#
# Bindings for GtkTreeView
#
binding "gtk-emacs-tree-view"
{
  bind "<ctrl>s" { "start-interactive-search" () }
  bind "<ctrl>f" { "move-cursor" (logical-positions, 1) }
  bind "<ctrl>b" { "move-cursor" (logical-positions, -1) }
}

#
# Bindings for menus
#
binding "gtk-emacs-menu"
{
  bind "<ctrl>n" { "move-current" (next) }
  bind "<ctrl>p" { "move-current" (prev) }
  bind "<ctrl>f" { "move-current" (child) }
  bind "<ctrl>b" { "move-current" (parent) }
}

class "GtkEntry" binding "gtk-emacs-text-entry"
class "GtkTextView" binding "gtk-emacs-text-entry"
class "GtkTextView" binding "gtk-emacs-text-view"
class "GtkTreeView" binding "gtk-emacs-tree-view"
class "GtkMenuShell" binding "gtk-emacs-menu"
EOF
fi

if [ ! -f usr/share/themes/Raleigh/gtk-2.0/gtkrc ] ; then
	mkdir -p usr/share/themes/Raleigh/gtk-2.0
	cat > usr/share/themes/Raleigh/gtk-2.0/gtkrc <<EOF
#
# This theme is the default theme if no other theme is selected.
#
EOF
fi
